package cn.com.sueframe.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;

/**
 * 
 * //��4��̬��ʾ����
 * @author anler Create Jul 6, 2012
 */
public class TextOverflow extends TagSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = -3076642027957612247L;
	private int length;
	private PageContext pageContext;
	private String content;
	private JspWriter out;

	@Override
	public int doStartTag() throws JspException {
		// TODO Auto-generated method stub
		out = pageContext.getOut();
		return EVAL_PAGE;
	}

	@Override
	public int doEndTag() throws JspException {
		// TODO Auto-generated method stub
		if(content == null){
			content = "";
		}
		content = content.replace("<", "��").replace(">", "��");
		try {
			if(content.trim().length() > length){
				content = "<span title='"+ content +"'>" + content.substring(0,length) + "..." +  "</span>";
			}
			out.write(content);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return EVAL_PAGE;
	}

	public int getLength() {
		return length;
	}

	public void setLength(int length) {
		this.length = length;
	}

	public PageContext getPageContext() {
		return pageContext;
	}

	public void setPageContext(PageContext pageContext) {
		this.pageContext = pageContext;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

}
